package com.kerust

import android.net.wifi.WifiManager
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.View
import android.widget.ArrayAdapter
import com.kerust.bean.BoardDevice
import com.kerust.interfaces.InternalFinderListener
import com.kerust.utils.FindBoardDevice
import javax.jmdns.JmDNS
import javax.jmdns.ServiceInfo
import javax.jmdns.ServiceListener

class MainActivity : AppCompatActivity() {
    lateinit var serviceInfo: ServiceInfo
    var jmDNS: JmDNS? = null
    var listener: ServiceListener? = null
    lateinit var wifi: WifiManager
    lateinit var lock: WifiManager.MulticastLock
    val TAG = MainActivity::class.java.simpleName
    private val type = "_http._tcp.local."//_airplay._tcp.local.
    var mList: MutableList<String>? = null
    lateinit var adapter: ArrayAdapter<String>
    lateinit var mBoardDevice: List<BoardDevice>
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.main)
        hideActionBar()

    }

    private fun hideActionBar() {
        val decorView = window.decorView
        val option = View.SYSTEM_UI_FLAG_FULLSCREEN
        decorView.systemUiVisibility = option
        val actionBar = supportActionBar
        actionBar?.hide()
    }



    override fun onStart() {
        super.onStart()
        FindBoardDevice.getInstance().callFunctionInBackground(this, object : InternalFinderListener {
            override fun findResult(devices: List<BoardDevice>) {
                devices.indices
                        .map { devices[it] }
                        .forEach { it -> Log.e("设备信息", it.id + it.name + it.uri) }
            }

        })
    }

    override fun onStop() {
        super.onStop()
        FindBoardDevice.getInstance().releasingResources()
    }
}
